/* Copyright (c) 2010 OFXKit
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#import "OFXKitTests.h"
#import "ofxkit.h"

@implementation OFXKitTests

- (void)setUp
{
    [super setUp];
    
    // Set-up code here.
}

- (void)tearDown
{
    // Tear-down code here.
    
    [super tearDown];
}

- (void) testOFX102Signup
{
  NSString* path = [[NSBundle bundleForClass:[self class]]
                    pathForResource:@"sample14_account_info_v102" ofType:@"ofx"];
  NSError* error;
  
  OFXDocumentResponse* document = 
  [OFXDocumentResponse ofxDocumentWithContentsOfFile:path
                                            encoding:NSASCIIStringEncoding
                                               error:&error];
  
  NSMutableArray* accountList = [[document accountInfo] accountList];
  STAssertEquals([accountList count], (NSUInteger)1, @"Account List Count");
  
  OFXAccount* account = [[OFXAccount alloc] init];
  [account setServiceStatus:@"ACTIVE"];
  [account setAccountId:@"5555555555"];
  [account setAccountType:@"CREDITCARD"];
  
  STAssertEqualObjects([accountList objectAtIndex:0], account, @"Account object");
}

- (void) testOFX102Banking
{
  NSString* path = [[NSBundle bundleForClass:[self class]] 
                    pathForResource:@"sample04_banking_v102" ofType:@"ofx"];
  NSError*  error;
  OFXDocumentResponse* document = [OFXDocumentResponse ofxDocumentWithContentsOfFile:path 
                                                                            encoding:NSASCIIStringEncoding 
                                                                               error:&error];
  STAssertEqualObjects([document headerVersion], @"100", @"OFX Header");
  
  OFXStatus* status = [[OFXStatus alloc] initWithName:nil
                                             withCode:@"0"
                                    withServerMessage:nil 
                                         withSeverity:@"INFO"];
  STAssertEqualObjects([[document signOnResponse] status], status,
                       @"SONRS STATUS");
  
  STAssertEqualObjects([document language], @"ENG", @"OFX Document Language");
  NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
  [dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];
  [dateFormatter setDateFormat:@"yyyyMMddHHmmss.SSS [Z:z]"];
  NSDate* serverDate = [dateFormatter dateFromString:@"20050831165056.000 [-8:PST]"];
  STAssertEqualObjects([document serverDate], serverDate, @"OFX Server Date");
  STAssertEquals([[document statements] count], (NSUInteger)2, 
                 @"Number of statements in document should be %d but was %d", 
                 2, [[document statements] count]);
  
  // check statement 1 values
  OFXStatement* statement1 = [[document statements] objectAtIndex:0];
  STAssertEqualObjects([statement1 transactionUID], @"0", 
                       @"Statement 1 transaction UID");
  STAssertEqualObjects([statement1 status], status, @"Statement 1 status");
  
  OFXCurrency* usd = [[OFXCurrency alloc] init];
  [usd setCurrencySymbol:@"USD"];
  STAssertEqualObjects([statement1 currency], usd, 
                       @"Statement 1 default currency");
  OFXBankAccount* account = [[OFXBankAccount alloc] init];
  [account setBankId:@"000000123"];
  [account setAccountId:@"123456"];
  [account setAccountType:@"CHECKING"];
  STAssertEqualObjects([statement1 account], account, 
                       @"Statement 1 account");
  
  // test transactions
  [dateFormatter setDateFormat:@"yyyyMMdd"];
  NSDate* startDate = [dateFormatter dateFromString:@"20050801"];
  STAssertEqualObjects([statement1 dateStart], startDate, 
                       @"Statement 1 transaction range, start");
  [dateFormatter setDateFormat:@"yyyyMMddHHmmss.SSS[Z:z]"];
  NSDate* endDate = [dateFormatter dateFromString:@"20050831165056.000[-8:PST]"];
  STAssertEqualObjects([statement1 dateEnd], endDate,
                       @"Statement 1 transaction range, end");
  
  OFXTransaction* transaction = [[OFXTransaction alloc] init];
  [transaction setTransactionType:@"PAYMENT"];
  [dateFormatter setDateFormat:@"yyyyMMddHHmmss"];
  NSDate* transactionDate = [dateFormatter dateFromString:@"20050824080000"];
  [transaction setDatePosted:transactionDate];
  [transaction setAmount:[NSNumber numberWithDouble:-80.32]];
  [transaction setUniqueId:@"219378"];
  [transaction setCheckNumber:@"1044"];
  OFXPayee* payee = [[OFXPayee alloc] init];
  [payee setName:@"FrogKick Scuba Gear"];
  [transaction setPayee:payee];
  
  STAssertEquals([[statement1 transactions] count], (NSUInteger)1, 
                 @"Statement 1 transaction count");  
  NSArray* transactions = [NSArray arrayWithObjects:transaction, nil];
  STAssertEqualObjects([statement1 transactions], transactions,
                       @"Statement 1 transactions");
  
  STAssertEqualObjects([statement1 ledgerBalance], 
                       [NSNumber numberWithDouble:2156.56], 
                       @"Statement 1 ledger balance");
  
  [dateFormatter setDateFormat:@"yyyyMMddHHmmss"];
  NSDate* ledgerBalanceValidAsOf = [dateFormatter dateFromString:@"20050831165056"];
  STAssertEqualObjects([statement1 ledgerBalanceValidAsOf], 
                       ledgerBalanceValidAsOf, 
                       @"Statement 1 ledger balance valid as of.");
  
  // check statement 2 values
  OFXStatement* statement2 = [[document statements] objectAtIndex:1];
  STAssertEqualObjects([statement2 transactionUID], @"0", 
                       @"Statement 2 transaction UID");
  STAssertEqualObjects([statement2 status], status, @"Statement 2 status");
  
  STAssertEqualObjects([statement2 currency], usd, 
                       @"Statement 2 default currency");
  account = [[OFXBankAccount alloc] init];
  [account setBankId:@"000000123"];
  [account setAccountId:@"654321"];
  [account setAccountType:@"SAVINGS"];
  STAssertEqualObjects([statement2 account], account, 
                       @"Statement 2 account");
  
  // test transactions
  [dateFormatter setDateFormat:@"yyyyMMdd"];
  startDate = [dateFormatter dateFromString:@"20050801"];
  STAssertEqualObjects([statement2 dateStart], startDate, 
                       @"Statement 2 transaction range, start");
  [dateFormatter setDateFormat:@"yyyyMMddHHmmss.SSS[Z:z]"];
  endDate = [dateFormatter dateFromString:@"20050831165056.000[-8:PST]"];
  STAssertEqualObjects([statement2 dateEnd], endDate,
                       @"Statement 2 transaction range, end");
  
  STAssertEquals([[statement2 transactions] count], (NSUInteger)0, 
                 @"Statement 2 transaction count");  
  transactions = [NSArray arrayWithObjects:nil];
  STAssertEqualObjects([statement2 transactions], transactions,
                       @"Statement 2 transactions");
  
  STAssertEqualObjects([statement2 ledgerBalance], 
                       [NSNumber numberWithDouble:3452.00], 
                       @"Statement 2 ledger balance");
  
  [dateFormatter setDateFormat:@"yyyyMMddHHmmss"];
  ledgerBalanceValidAsOf = [dateFormatter dateFromString:@"20050831165056"];
  STAssertEqualObjects([statement2 ledgerBalanceValidAsOf], 
                       ledgerBalanceValidAsOf, 
                       @"Statement 2 ledger balance valid as of.");  
}

- (void) testOFX102Investments
{
  NSString* path = [[NSBundle bundleForClass:[self class]] 
                    pathForResource:@"sample02_inv_v102" ofType:@"ofx"];
  NSError*  error;
  OFXDocumentResponse* document = [OFXDocumentResponse ofxDocumentWithContentsOfFile:path 
                                                                            encoding:NSASCIIStringEncoding 
                                                                               error:&error];
  STAssertEqualObjects([document headerVersion], @"100", @"OFX Header");
  
  OFXStatus* status = [[OFXStatus alloc] initWithName:nil
                                             withCode:@"0"
                                    withServerMessage:nil 
                                         withSeverity:@"INFO"];
  STAssertEqualObjects([[document signOnResponse] status], status,
                       @"SONRS STATUS");
  
  STAssertEqualObjects([document language], @"ENG", @"OFX Document Language");
  NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
  [dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];
  [dateFormatter setDateFormat:@"yyyyMMddHHmmss.SSS [Z:z]"];
  NSDate* serverDate = [dateFormatter dateFromString:@"20050831165324.000 [-8:PST]"];
  STAssertEqualObjects([document serverDate], serverDate, @"OFX Server Date");
  
  // there should only be 1 statement
  STAssertEquals([[document statements] count], (NSUInteger)1,
                 @"Number of statements in document");
  OFXInvestmentStatement* statement = [[document statements] objectAtIndex:0];
  STAssertEqualObjects([statement transactionUID], 
                       @"0", @"Statement transactionUid");
  STAssertEqualObjects([statement status], status, @"Statement status.");
  
  // check transactions
  STAssertEquals([[statement transactions] count], (NSUInteger)1,
                 @"Statement transaction count.");
  
  OFXBuyMutualFund* buyMutualFund = [[OFXBuyMutualFund alloc] init];
  [buyMutualFund setUniqueId:@"40025098199608029240"];
  [dateFormatter setDateFormat:@"yyyyMMdd"];
  [buyMutualFund setTradeDate:[dateFormatter dateFromString:@"20050802"]];
  [buyMutualFund setMemo:@"MONEY MARKET FUND"];
  OFXMutualFund* security = [[OFXMutualFund alloc] init];
  [security setUniqueId:@"808515100"];
  [security setUniqueIdType:@"CUSIP"];
  [security setName:@"MONEY MARKET FUND"];
  [security setTickerSymbol:@"SWMXX"];
  [security setMutualFundType:@"OPENEND"];
  [buyMutualFund setSecurity:security];
  [buyMutualFund setUnits:[NSNumber numberWithDouble:120.00]];
  [buyMutualFund setUnitPrice:[NSNumber numberWithDouble:1.0000]];
  [buyMutualFund setCommission:[NSNumber numberWithDouble:0.00]];
  [buyMutualFund setTotalAmount:[NSNumber numberWithDouble:-120.00]];
  [buyMutualFund setSecuritySubAccount:@"CASH"];
  [buyMutualFund setFundingSubAccount:@"CASH"];
  [buyMutualFund setBuyType:@"BUY"];
  
  NSArray* transactions = [NSArray arrayWithObjects:buyMutualFund, nil];
  STAssertEqualObjects([statement transactions], transactions,
                       @"Statment transactions");
  
  // check positions
  OFXInvestmentPositionMutualFund* mutualFundPosition = 
  [[OFXInvestmentPositionMutualFund alloc] init];
  [mutualFundPosition setSecurity:security];
  [mutualFundPosition setHeldInAccount:@"OTHER"];
  [mutualFundPosition setPositionType:@"LONG"];
  [mutualFundPosition setUnits:[NSNumber numberWithDouble:1560.18]];
  [mutualFundPosition setUnitPrice:[NSNumber numberWithInt:1]];
  [mutualFundPosition setMarketValue:[NSNumber numberWithDouble:156.18]];
  [mutualFundPosition setPriceAndValueValidAsOf:[dateFormatter dateFromString:@"20050831"]];
  [mutualFundPosition setMemo:@"MONEY MARKET FUND"];
  
  STAssertEquals([[statement positions] count], (NSUInteger)1,
                 @"Statement position count");
  STAssertEqualObjects([statement positions], 
                       [NSArray arrayWithObject:mutualFundPosition],
                       @"Statement positions");
  
  // check investment balance
  STAssertEqualObjects([statement availableBalance],
                       [NSNumber numberWithDouble:370.87],
                       @"Statement available balance");
  STAssertEqualObjects([statement marginBalance], 
                       [NSNumber numberWithDouble:0.00],
                       @"Statement margin balance");
  STAssertEqualObjects([statement shortBalance], 
                       [NSNumber numberWithDouble:0.00], 
                       @"Statment short balance");
}

- (void) testOFX211Investments
{
  NSString* path = [[NSBundle bundleForClass:[self class]] 
                    pathForResource:@"sample01_inv_v211" ofType:@"ofx"];
  NSError*  error;
  OFXDocumentResponse* document = [OFXDocumentResponse ofxDocumentWithContentsOfFile:path 
                                                                            encoding:NSASCIIStringEncoding 
                                                                               error:&error];
  STAssertEqualObjects([document headerVersion], @"200", @"OFX Header");
  
  OFXStatus* status = [[OFXStatus alloc] initWithName:nil
                                             withCode:@"0"
                                    withServerMessage:nil 
                                         withSeverity:@"INFO"];
  STAssertEqualObjects([[document signOnResponse] status], status,
                       @"SONRS STATUS");
  
  STAssertEqualObjects([document language], @"ENG", @"OFX Document Language");
  NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
  [dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];
  [dateFormatter setDateFormat:@"yyyyMMddHHmmss.SSS [Z:z]"];
  NSDate* serverDate = [dateFormatter dateFromString:@"20050831165324.000 [-8:PST]"];
  STAssertEqualObjects([document serverDate], serverDate, @"OFX Server Date");
  
  STAssertEquals([[document statements] count], (NSUInteger)1,
                 @"Number of statements in document");
  OFXInvestmentStatement* statement = [[document statements] objectAtIndex:0];
  STAssertEqualObjects([statement transactionUID], 
                       @"0", @"Statement transactionUid");
  STAssertEqualObjects([statement status], status, @"Statement status.");
  
  OFXInvestmentAccount*  account = [[OFXInvestmentAccount alloc] init];
  [account setBrokerId:@"Broker Site"];
  [account setAccountId:@"1256734"];
  STAssertEqualObjects([statement account], account, @"Investment account");
  
  // check transactions
  STAssertEquals([[statement transactions] count], (NSUInteger)1,
                 @"Statement transaction count.");
  
  OFXBuyMutualFund* buyMutualFund = [[OFXBuyMutualFund alloc] init];
  [buyMutualFund setUniqueId:@"40025098199608029240"];
  [dateFormatter setDateFormat:@"yyyyMMdd"];
  [buyMutualFund setTradeDate:[dateFormatter dateFromString:@"20030802"]];
  [buyMutualFund setMemo:@"MONEY MARKET FUND"];
  OFXMutualFund* security = [[OFXMutualFund alloc] init];
  [security setUniqueId:@"808515100"];
  [security setUniqueIdType:@"CUSIP"];
  [security setName:@"MONEY MARKET FUND"];
  [security setTickerSymbol:@"SWMXX"];
  [security setMutualFundType:@"OPENEND"];
  [buyMutualFund setSecurity:security];
  [buyMutualFund setUnits:[NSNumber numberWithDouble:120.00]];
  [buyMutualFund setUnitPrice:[NSNumber numberWithDouble:1.0000]];
  [buyMutualFund setCommission:[NSNumber numberWithDouble:0.00]];
  [buyMutualFund setTotalAmount:[NSNumber numberWithDouble:-120.00]];
  [buyMutualFund setSecuritySubAccount:@"CASH"];
  [buyMutualFund setFundingSubAccount:@"CASH"];
  [buyMutualFund setBuyType:@"BUY"];
  
  NSArray* transactions = [NSArray arrayWithObjects:buyMutualFund, nil];
  STAssertEqualObjects([statement transactions], transactions,
                       @"Statment transactions");
  
  // check positions
  OFXInvestmentPositionMutualFund* mutualFundPosition = 
  [[OFXInvestmentPositionMutualFund alloc] init];
  [mutualFundPosition setSecurity:security];
  [mutualFundPosition setHeldInAccount:@"OTHER"];
  [mutualFundPosition setPositionType:@"LONG"];
  [mutualFundPosition setUnits:[NSNumber numberWithDouble:1560.18]];
  [mutualFundPosition setUnitPrice:[NSNumber numberWithInt:1]];
  [mutualFundPosition setMarketValue:[NSNumber numberWithDouble:156.18]];
  [mutualFundPosition setPriceAndValueValidAsOf:[dateFormatter dateFromString:@"20050831"]];
  [mutualFundPosition setMemo:@"MONEY MARKET FUND"];
  
  STAssertEquals([[statement positions] count], (NSUInteger)1,
                 @"Statement position count");
  STAssertEqualObjects([statement positions], 
                       [NSArray arrayWithObject:mutualFundPosition],
                       @"Statement positions");
  
  // check investment balance
  STAssertEqualObjects([statement availableBalance],
                       [NSNumber numberWithDouble:370.87],
                       @"Statement available balance");
  STAssertEqualObjects([statement marginBalance], 
                       [NSNumber numberWithDouble:0.00],
                       @"Statement margin balance");
  STAssertEqualObjects([statement shortBalance], 
                       [NSNumber numberWithDouble:0.00], 
                       @"Statment short balance");
}

- (void) testOFX211Banking
{
  NSString* path = [[NSBundle bundleForClass:[self class]] 
                    pathForResource:@"sample03_banking_v211" ofType:@"ofx"];
  NSError*  error;
  OFXDocumentResponse* document = [OFXDocumentResponse ofxDocumentWithContentsOfFile:path 
                                                                            encoding:NSASCIIStringEncoding 
                                                                               error:&error];
  STAssertEqualObjects([document headerVersion], @"200", @"OFX Header");
  
  OFXStatus* status = [[OFXStatus alloc] initWithName:nil
                                             withCode:@"0"
                                    withServerMessage:nil 
                                         withSeverity:@"INFO"];
  STAssertEqualObjects([[document signOnResponse] status], status,
                       @"SONRS STATUS");
  
  STAssertEqualObjects([document language], @"ENG", @"OFX Document Language");
  NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
  [dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];
  [dateFormatter setDateFormat:@"yyyyMMddHHmmss.SSS [Z:z]"];
  NSDate* serverDate = [dateFormatter dateFromString:@"20050831165153.000 [-8:PST]"];
  STAssertEqualObjects([document serverDate], serverDate, @"OFX Server Date");
  
  OFXStatement* statement1 = [[document statements] objectAtIndex:0];
  STAssertEqualObjects([statement1 transactionUID], @"0", 
                       @"Statement 1 transaction UID");
  STAssertEqualObjects([statement1 status], status, @"Statement 1 status");
  
  OFXCurrency* usd = [[OFXCurrency alloc] init];
  [usd setCurrencySymbol:@"USD"];
  STAssertEqualObjects([statement1 currency], usd, 
                       @"Statement 1 default currency");
  OFXBankAccount* account = [[OFXBankAccount alloc] init];
  [account setBankId:@"000000123"];
  [account setAccountId:@"123456-90"];
  [account setAccountType:@"CREDITLINE"];
  STAssertEqualObjects([statement1 account], account, 
                       @"Statement 1 account");
  
  STAssertEquals([[statement1 transactions] count], (NSUInteger)0, 
                 @"Statement 1 transaction count");
  
  STAssertEqualObjects([statement1 ledgerBalance], 
                       [NSNumber numberWithDouble:-4367.00], 
                       @"Statement 1 ledger balance");
  
  [dateFormatter setDateFormat:@"yyyyMMddHHmmss"];
  NSDate* ledgerBalanceValidAsOf = [dateFormatter dateFromString:@"20050831165153"];
  STAssertEqualObjects([statement1 ledgerBalanceValidAsOf], 
                       ledgerBalanceValidAsOf, 
                       @"Statement 1 ledger balance valid as of."); 
  
  STAssertEqualObjects([statement1 availableBalance],
                       [NSNumber numberWithDouble:5633.00],
                       @"Statment 1 available balance");
  
  STAssertEqualObjects([statement1 availableBalanceValidAsOf], 
                       [dateFormatter dateFromString:@"20050831165153"], 
                       @"Statement 1 available balance valid as of."); 
  
  // check additional balances
  OFXBalance* balance = [[OFXBalance alloc] init];
  [balance setName:@"Interest"];
  [balance setBalanceDescription:@"Interest Year To Date"];
  [balance setBalanceType:@"DOLLAR"];
  [balance setValue:[NSNumber numberWithDouble:117.89]];
  [balance setValidAsOf:[dateFormatter dateFromString:@"20050831165153"]];
  NSArray* balances = [NSArray arrayWithObject:balance];
  STAssertEqualObjects([statement1 otherBalances], balances,
                       @"Statement other balances");
}

- (void) testOFX211BankingCredit
{
  NSString* path = [[NSBundle bundleForClass:[self class]] 
                    pathForResource:@"sample05_banking_credit_v211" 
                    ofType:@"ofx"];
  NSError*  error;
  OFXDocumentResponse* document = [OFXDocumentResponse ofxDocumentWithContentsOfFile:path 
                                                                            encoding:NSASCIIStringEncoding 
                                                                               error:&error];
  STAssertEqualObjects([document headerVersion], @"200", @"OFX Header");
  OFXStatus* status = [[OFXStatus alloc] initWithName:nil
                                             withCode:@"0"
                                    withServerMessage:nil 
                                         withSeverity:@"INFO"];
  STAssertEqualObjects([[document signOnResponse] status], status,
                       @"SONRS STATUS");
  
  STAssertEqualObjects([document language], @"ENG", @"OFX Document Language");
  NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
  [dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];
  [dateFormatter setDateFormat:@"yyyyMMddHHmmss.SSS [Z:z]"];
  NSDate* serverDate = [dateFormatter dateFromString:@"20050831165153.000 [-8:PST]"];
  STAssertEqualObjects([document serverDate], serverDate, @"OFX Server Date");
  
  OFXStatement* statement1 = [[document statements] objectAtIndex:0];
  STAssertEqualObjects([statement1 transactionUID], @"0", 
                       @"Statement 1 transaction UID");
  STAssertEqualObjects([statement1 status], status, @"Statement 1 status");
  
  OFXCurrency* usd = [[OFXCurrency alloc] init];
  [usd setCurrencySymbol:@"USD"];
  STAssertEqualObjects([statement1 currency], usd, 
                       @"Statement 1 default currency");
  OFXBankAccount* account = [[OFXBankAccount alloc] init];
  [account setBankId:@"000000123"];
  [account setAccountId:@"123456"];
  [account setAccountType:@"CHECKING"];
  STAssertEqualObjects([statement1 account], account, 
                       @"Statement 1 account");
  
  [dateFormatter setDateFormat:@"yyyyMMdd"];
  NSDate* startDate = [dateFormatter dateFromString:@"20040801"];
  STAssertEqualObjects([statement1 dateStart], startDate, 
                       @"Statement 1 transaction range, start");
  [dateFormatter setDateFormat:@"yyyyMMddHHmmss.SSS[Z:z]"];
  NSDate* endDate = [dateFormatter dateFromString:@"20050831165153.000[-8:PST]"];
  STAssertEqualObjects([statement1 dateEnd], endDate,
                       @"Statement 1 transaction range, end");
  
  STAssertEquals([[statement1 transactions] count], (NSUInteger)1, 
                 @"Statement 1 transaction count");
  
  OFXTransaction* transaction = [[OFXTransaction alloc] init];
  [transaction setTransactionType:@"POS"];
  [dateFormatter setDateFormat:@"yyyyMMddHHmmss"];
  NSDate* transactionDate = [dateFormatter dateFromString:@"20050824080000"];
  [transaction setDatePosted:transactionDate];
  [transaction setAmount:[NSNumber numberWithDouble:-80.00]];
  [transaction setUniqueId:@"219378"];
  OFXPayee* payee = [[OFXPayee alloc] init];
  [payee setName:@"FrogKick Scuba Gear"];
  [transaction setPayee:payee];
  
  STAssertEquals([[statement1 transactions] count], (NSUInteger)1, 
                 @"Statement 1 transaction count");  
  NSArray* transactions = [NSArray arrayWithObjects:transaction, nil];
  STAssertEqualObjects([statement1 transactions], transactions,
                       @"Statement 1 transactions");
  
  
  STAssertEqualObjects([statement1 ledgerBalance], 
                       [NSNumber numberWithDouble:2156.56], 
                       @"Statement 1 ledger balance");
  
  [dateFormatter setDateFormat:@"yyyyMMddHHmmss"];
  NSDate* ledgerBalanceValidAsOf = [dateFormatter dateFromString:@"20050831165153"];
  STAssertEqualObjects([statement1 ledgerBalanceValidAsOf], 
                       ledgerBalanceValidAsOf, 
                       @"Statement 1 ledger balance valid as of."); 
  
  // credit card statement
  OFXStatement* statement2 = [[document statements] objectAtIndex:1];
  STAssertEqualObjects([statement2 transactionUID], @"0", 
                       @"Statement 2 transaction UID");
  STAssertEqualObjects([statement2 status], status, @"Statement 2 status");
  
  usd = [[OFXCurrency alloc] init];
  [usd setCurrencySymbol:@"USD"];
  STAssertEqualObjects([statement2 currency], usd, 
                       @"Statement 2 default currency");
  OFXAccount* account2 = [[OFXAccount alloc] init];
  [account2 setAccountId:@"123412341234"];
  [account2 setAccountType:@"CREDITCARD"];
  STAssertEqualObjects([statement2 account], account2, 
                       @"Statement 2 account");
  
  [dateFormatter setDateFormat:@"yyyyMMdd"];
  startDate = [dateFormatter dateFromString:@"20050801"];
  STAssertEqualObjects([statement2 dateStart], startDate, 
                       @"Statement 2 transaction range, start");
  [dateFormatter setDateFormat:@"yyyyMMddHHmmss.SSS[Z:z]"];
  endDate = [dateFormatter dateFromString:@"20050831165153.000[-8:PST]"];
  STAssertEqualObjects([statement2 dateEnd], endDate,
                       @"Statement 2 transaction range, end");
  
  STAssertEquals([[statement2 transactions] count], (NSUInteger)2, 
                 @"Statement 2 transaction count");
  
  transaction = [[OFXTransaction alloc] init];
  [transaction setTransactionType:@"INT"];
  [dateFormatter setDateFormat:@"yyyyMMddHHmmss"];
  [transaction setDatePosted:[dateFormatter dateFromString:@"20050811080000"]];
  [transaction setAmount:[NSNumber numberWithDouble:-23.00]];
  [transaction setUniqueId:@"219867"];
  payee = [[OFXPayee alloc] init];
  [payee setName:@"Interest Charge"];
  [transaction setPayee:payee];
  
  OFXTransaction* transaction1 = [[OFXTransaction alloc] init];
  [transaction1 setTransactionType:@"CREDIT"];
  [dateFormatter setDateFormat:@"yyyyMMddHHmmss"];
  [transaction1 setDatePosted:[dateFormatter dateFromString:@"20050811080000"]];
  [transaction1 setAmount:[NSNumber numberWithDouble:350.00]];
  [transaction1 setUniqueId:@"219868"];
  payee = [[OFXPayee alloc] init];
  [payee setName:@"Payment - Thank You"];
  [transaction1 setPayee:payee];
  
  STAssertEquals([[statement2 transactions] count], (NSUInteger)2, 
                 @"Statement 2 transaction count");  
  
  NSArray* transactions2 = [NSArray arrayWithObjects:transaction, transaction1, 
                            nil];
  STAssertEqualObjects([statement2 transactions], transactions2,
                       @"Statement 2 transactions");
  
  STAssertEqualObjects([statement2 ledgerBalance], 
                       [NSNumber numberWithDouble:-562.00], 
                       @"Statement 1 ledger balance");
  
  [dateFormatter setDateFormat:@"yyyyMMddHHmmss"];
  ledgerBalanceValidAsOf = [dateFormatter dateFromString:@"20050831165153"];
  STAssertEqualObjects([statement2 ledgerBalanceValidAsOf], 
                       ledgerBalanceValidAsOf, 
                       @"Statement 2 ledger balance valid as of."); 
}

- (void) testOFX211MFA
{
  NSString* path = [[NSBundle bundleForClass:[self class]] 
                    pathForResource:@"sample07_mfa_v211" ofType:@"ofx"];
  NSError*  error;
  OFXDocumentResponse* document = [OFXDocumentResponse ofxDocumentWithContentsOfFile:path 
                                                                            encoding:NSASCIIStringEncoding 
                                                                               error:&error];
  STAssertEqualObjects([document headerVersion], @"200", @"OFX Header");
  
  OFXStatus* status = [[OFXStatus alloc] initWithName:nil
                                             withCode:@"3000"
                                    withServerMessage:nil 
                                         withSeverity:@"ERROR"];  
  STAssertEqualObjects([[document signOnResponse] status], status, 
                       @"SONRS STATUS");
  
  STAssertEqualObjects([document language], @"ENG", @"OFX Document Language");
  NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
  [dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];
  [dateFormatter setDateFormat:@"yyyyMMddHHmmss.SSS [Z:z]"];
  NSDate* serverDate = [dateFormatter dateFromString:@"20050831165153.000 [-8:PST]"];
  STAssertEqualObjects([document serverDate], serverDate, @"OFX Server Date");
  
  OFXMultiFactorAuthentication* mfa1 = [[OFXMultiFactorAuthentication alloc] init];
  [mfa1 setPhraseId:@"MFA_4"];
  [mfa1 setPhraseLabel:@"Father's middle name"];
  OFXMultiFactorAuthentication* mfa2 = [[OFXMultiFactorAuthentication alloc] init];
  [mfa2 setPhraseId:@"MFA_12"];
  [mfa2 setPhraseLabel:@"Last four digits of your home phone number"];
  OFXMultiFactorAuthentication* mfa3 = [[OFXMultiFactorAuthentication alloc] init];
  [mfa3 setPhraseId:@"MFA_18"];
  [mfa3 setPhraseLabel:@"Name of the company where you had your first job"];
  
  NSArray* challengers = [NSArray arrayWithObjects:mfa1, mfa2, mfa3, nil];
  STAssertEqualObjects([[document signOnResponse] multiFactorAuthentication], 
                       challengers, @"Multifactor authentication.");
}

- (void) testOFXBankingSample08
{
  NSString* path = [[NSBundle bundleForClass:[self class]] 
                    pathForResource:@"sample08_banking" ofType:@"ofx"];  
  NSError*  error;
  OFXDocumentResponse* document = [OFXDocumentResponse ofxDocumentWithContentsOfFile:path 
                                                                            encoding:NSASCIIStringEncoding 
                                                                               error:&error];
  STAssertEqualObjects([document headerVersion], @"200", @"OFX Header");
  
  OFXSignOn* signOn = [[OFXSignOn alloc] init];
  OFXStatus* status = [[OFXStatus alloc] initWithName:nil
                                             withCode:@"0"
                                    withServerMessage:nil 
                                         withSeverity:@"INFO"];
  
  NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
  [dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];
  [dateFormatter setDateFormat:@"yyyyMMddHHmmss.SSS [Z:z]"];
  [dateFormatter setDateFormat:@"yyyyMMddHHmmss"];
  
  [signOn setStatus:status];
  [signOn setDateProfileUpdated:[dateFormatter dateFromString:@"19991029101003"]];
  [signOn setDateAccountUpdated:[dateFormatter dateFromString:@"20031029101003"]];
  
  OFXFinancialInstitution* financialInstitution = [[OFXFinancialInstitution alloc] init];
  [financialInstitution setOrganization:@"NCH"];
  [financialInstitution setFinancialInstitutionId:@"1001"];
  [signOn setFinancialInstitution:financialInstitution];
  
  STAssertEqualObjects([document signOnResponse], signOn, @"SONRS");
  
  STAssertEqualObjects([document language], @"ENG", @"OFX Document Language");
  
  OFXStatement* statement1 = [[document statements] objectAtIndex:0];
  STAssertEqualObjects([statement1 transactionUID], @"1001", 
                       @"Statement 1 transaction UID");
  STAssertEqualObjects([statement1 status], status, @"Statement 1 status");
  
  OFXCurrency* usd = [[OFXCurrency alloc] init];
  [usd setCurrencySymbol:@"USD"];
  STAssertEqualObjects([statement1 currency], usd, 
                       @"Statement 1 default currency");
  OFXBankAccount* account = [[OFXBankAccount alloc] init];
  [account setBankId:@"121099999"];
  [account setAccountId:@"999988"];
  [account setAccountType:@"CHECKING"];
  STAssertEqualObjects([statement1 account], account, @"Statement 1 account");
  
  STAssertEquals([[statement1 transactions] count], (NSUInteger)2, 
                 @"Statement 1 transaction count");
  
  [dateFormatter setDateFormat:@"yyyyMMdd"];
  OFXTransaction* trn1 = [[OFXTransaction alloc] init];
  OFXTransaction* trn2 = [[OFXTransaction alloc] init];
  [trn1 setTransactionType:@"CHECK"];
  [trn2 setTransactionType:@"ATM"];
  [trn1 setDatePosted:[dateFormatter dateFromString:@"20051004"]];
  [trn2 setDatePosted:[dateFormatter dateFromString:@"20051020"]];
  [trn2 setDateInitiated:[dateFormatter dateFromString:@"20051020"]];
  [trn1 setAmount:[NSNumber numberWithDouble:-200.00]];
  [trn2 setAmount:[NSNumber numberWithDouble:-300.00]];
  [trn1 setUniqueId:@"00002"];
  [trn2 setUniqueId:@"00003"];
  [trn1 setCheckNumber:@"1000"];
  
  NSArray* statementTransactions = [statement1 transactions];
  NSArray* checkTransactions = [NSArray arrayWithObjects:trn1,trn2,nil];
  STAssertEqualObjects(statementTransactions, checkTransactions, 
                       @"Transactions"); 
  
  STAssertEqualObjects([statement1 ledgerBalance], 
                       [NSNumber numberWithDouble:200.29], 
                       @"Statement 1 ledger balance");
  
  [dateFormatter setDateFormat:@"yyyyMMddHHmm"];
  NSDate* ledgerBalanceValidAsOf = [dateFormatter dateFromString:@"200510291120"];
  STAssertEqualObjects([statement1 ledgerBalanceValidAsOf], 
                       ledgerBalanceValidAsOf, 
                       @"Statement 1 ledger balance valid as of."); 
  
  STAssertEqualObjects([statement1 availableBalance],
                       [NSNumber numberWithDouble:200.29],
                       @"Statment 1 available balance");
  
  STAssertEqualObjects([statement1 availableBalanceValidAsOf], 
                       [dateFormatter dateFromString:@"200510291120"], 
                       @"Statement 1 available balance valid as of."); 
}

- (void) testOFXInvestmentSample12
{
  NSString* path = [[NSBundle bundleForClass:[self class]] 
                    pathForResource:@"sample12_investment" ofType:@"ofx"];  
  NSError*  error;
  OFXDocumentResponse* document = [OFXDocumentResponse ofxDocumentWithContentsOfFile:path 
                                                                            encoding:NSASCIIStringEncoding 
                                                                               error:&error];
  STAssertEqualObjects([document headerVersion], @"200", @"OFX Header");
  
  OFXStatus* status = [[OFXStatus alloc] initWithName:nil
                                             withCode:@"0"
                                    withServerMessage:nil 
                                         withSeverity:@"INFO"];
  
  NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
  [dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];
  [dateFormatter setDateFormat:@"yyyyMMddHHmmss"];
  
  OFXInvestmentStatement* statement = [[OFXInvestmentStatement alloc] init];
  [statement setStatus:status];
  [statement setTransactionUID:@"1001"];
  [statement setStatementAsOf:[dateFormatter dateFromString:@"20050827010000"]];
  OFXCurrency* currency = [[OFXCurrency alloc] init];
  [currency setCurrencySymbol:@"USD"];
  [statement setCurrency:currency];
  OFXInvestmentAccount* account = [[OFXInvestmentAccount alloc] init];
  [account setBrokerId:@"121099999"];
  [account setAccountId:@"999988"];
  [statement setAccount:account];
  [statement setDateStart:[dateFormatter dateFromString:@"20050824130105"]];
  [statement setDateEnd:[dateFormatter dateFromString:@"20050828101000"]];
  
  // build up transactions
  [dateFormatter setDateFormat:@"yyyyMMdd"];
  OFXBuyStock* trn1 = [[OFXBuyStock alloc] init];
  [trn1 setUniqueId:@"23321"];
  [trn1 setTradeDate:[dateFormatter dateFromString:@"20050825"]];
  [trn1 setSettlementDate:[dateFormatter dateFromString:@"20050828"]];
  OFXStock* acmeStock = [[OFXStock alloc] init];
  [acmeStock setUniqueId:@"123456789"];
  [acmeStock setUniqueIdType:@"CUSIP"];
  [acmeStock setName:@"Acme Development, Inc."];
  [acmeStock setTickerSymbol:@"ACME"];
  [acmeStock setFinancialInstitutionSecurityId:@"1024"];
  [acmeStock setYield:[NSNumber numberWithInt:10]];
  [acmeStock setAssetClass:@"SMALLSTOCK"];
  [trn1 setSecurity:acmeStock];
  [trn1 setUnits:[NSNumber numberWithInt:100]];
  [trn1 setUnitPrice:[NSNumber numberWithInt:50]];
  [trn1 setCommission:[NSNumber numberWithInt:25]];
  [trn1 setTotalAmount:[NSNumber numberWithInt:-5025]];
  [trn1 setSecuritySubAccount:@"CASH"];
  [trn1 setFundingSubAccount:@"CASH"];
  [trn1 setBuyType:@"BUY"];
  
  OFXInvestmentBankTransaction* trn2 = [[OFXInvestmentBankTransaction alloc] init];
  [trn2 setTransactionType:@"CREDIT"];
  [trn2 setDatePosted:[dateFormatter dateFromString:@"20050825"]];
  [trn2 setDateInitiated:[dateFormatter dateFromString:@"20050825"]];
  [trn2 setAmount:[NSNumber numberWithInt:1000]];
  [trn2 setUniqueId:@"12345"];
  OFXPayee* payee = [[OFXPayee alloc] init];
  [payee setName:@"Customer deposit"];
  [trn2 setPayee:payee];
  [trn2 setMemo:@"Your check #1034"];
  [trn2 setFundingSubAccount:@"CASH"];
  
  NSMutableArray* transactions = [NSMutableArray arrayWithObjects:trn1, trn2, 
                                  nil];
  [statement setTransactions:transactions];
  
  // build up positions
  [dateFormatter setDateFormat:@"yyyyMMddHHmmss"];
  OFXInvestmentPositionStock*  pos1 = [[OFXInvestmentPositionStock alloc] init];
  [pos1 setSecurity:acmeStock];
  [pos1 setHeldInAccount:@"CASH"];
  [pos1 setPositionType:@"LONG"];
  [pos1 setUnits:[NSNumber numberWithInt:200]];
  [pos1 setUnitPrice:[NSNumber numberWithDouble:49.50]];
  [pos1 setMarketValue:[NSNumber numberWithInt:9900]];
  [pos1 setPriceAndValueValidAsOf:[dateFormatter dateFromString:@"20050827010000"]];
  [pos1 setMemo:@"Next dividend payable Sept 1"];
  
  [dateFormatter setDateFormat:@"yyyyMMdd"];
  OFXInvestmentPositionOption* pos2 = [[OFXInvestmentPositionOption alloc] init];
  OFXOption* option = [[OFXOption alloc] init];
  [option setUniqueId:@"000342222"];
  [option setUniqueIdType:@"CUSIP"];
  [option setName:@"Lucky Airlines Jan 97 Put"];
  [option setTickerSymbol:@"LUAXX"];
  [option setFinancialInstitutionSecurityId:@"0013"];
  [option setOptionType:@"PUT"];
  [option setStrikePrice:[NSNumber numberWithDouble:35.00]];
  [option setExpirationDate:[dateFormatter dateFromString:@"20050121"]];
  [option setSharesPerContract:[NSNumber numberWithInt:100]];
  [option setAssetClass:@"LARGESTOCK"];
  OFXSecurity* security = [[OFXSecurity alloc] init];
  [security setUniqueId:@"000342200"];
  [security setUniqueIdType:@"CUSIP"];
  [option setSecurity:security];
  
  [dateFormatter setDateFormat:@"yyyyMMddHHmmss"];
  [pos2 setSecurity:option];
  [pos2 setHeldInAccount:@"CASH"];
  [pos2 setPositionType:@"LONG"];
  [pos2 setUnits:[NSNumber numberWithInt:1]];
  [pos2 setUnitPrice:[NSNumber numberWithDouble:5.00]];
  [pos2 setMarketValue:[NSNumber numberWithDouble:500.00]];
  [pos2 setPriceAndValueValidAsOf:[dateFormatter dateFromString:@"20050827010000"]];
  [pos2 setMemo:@"Option is in the money"];
  [statement setPositions:[NSArray arrayWithObjects:pos1, pos2, nil]];
  
  // build balance list
  [statement setAvailableBalance:[NSNumber numberWithInt:200]];
  [statement setMarginBalance:[NSNumber numberWithInt:-50]];
  [statement setShortBalance:[NSNumber numberWithInt:0]];
  
  OFXBalance* bal = [[OFXBalance alloc] init];
  [bal setName:@"Margin Interest Rate"];
  [bal setBalanceDescription:@"Current interest rate on margin balances"];
  [bal setBalanceType:@"PERCENT"];
  [bal setValue:[NSNumber numberWithDouble:7.85]];
  [bal setValidAsOf:[dateFormatter dateFromString:@"20050827010000"]];
  [statement setOtherBalances:[NSArray arrayWithObject:bal]];
  
  // build open orders
  OFXInvestmentOrderBuyStock* buyStock = [[OFXInvestmentOrderBuyStock alloc] init];
  [buyStock setUniqueId:@"23321"];
  OFXStock* stock = [[OFXStock alloc] init];
  [stock setUniqueId:@"666678578"];
  [stock setUniqueIdType:@"CUSIP"];
  [stock setName:@"Hackson Unlimited, Inc."];
  [stock setTickerSymbol:@"HACK"];
  [stock setFinancialInstitutionSecurityId:@"1027"];
  [stock setYield:[NSNumber numberWithInt:17]];
  [stock setAssetClass:@"SMALLSTOCK"];
  [buyStock setSecurity:stock];
  [buyStock setDatePlaced:[dateFormatter dateFromString:@"20050624031505"]];
  [buyStock setUnits:[NSNumber numberWithInt:100]];
  [buyStock setSubAccount:@"CASH"];
  [buyStock setOrderDuration:@"GOODTILCANCEL"];
  [buyStock setOrderRestrictions:@"NONE"];
  [buyStock setLimitPrice:[NSNumber numberWithInt:50]];
  [buyStock setBuyType:@"BUY"];
  
  [statement setOpenOrders:[NSArray arrayWithObject:buyStock]];
  
  STAssertEqualObjects([[document statements] objectAtIndex:0], statement,
                       @"Statement");
}

- (void) testOFXInvestmentSample13
{
  NSString* path = [[NSBundle bundleForClass:[self class]] 
                    pathForResource:@"sample13_investment_401k" ofType:@"ofx"];  
  NSError*  error;
  OFXDocumentResponse* document = [OFXDocumentResponse ofxDocumentWithContentsOfFile:path 
                                                                            encoding:NSASCIIStringEncoding 
                                                                               error:&error];
  STAssertEqualObjects([document headerVersion], @"200", @"OFX Header");
  
  OFXStatus* status = [[OFXStatus alloc] initWithName:nil
                                             withCode:@"0"
                                    withServerMessage:nil 
                                         withSeverity:@"INFO"];
  
  NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
  [dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];
  [dateFormatter setDateFormat:@"yyyyMMddHHmmss.SSS[Z:z]"];
  
  OFX401kInvestmentStatement* statement = [[OFX401kInvestmentStatement alloc] init];
  [statement setStatus:status];
  [statement setTransactionUID:@"1002"];
  [statement setStatementAsOf:[dateFormatter dateFromString:@"20060131172605.000[-4:EST]"]];
  OFXCurrency* currency = [[OFXCurrency alloc] init];
  [currency setCurrencySymbol:@"USD"];
  [statement setCurrency:currency];
  OFXInvestmentAccount* account = [[OFXInvestmentAccount alloc] init];
  [account setBrokerId:@"121099999"];
  [account setAccountId:@"999988"];
  [statement setAccount:account];
  
  [statement setDateStart:[dateFormatter dateFromString:@"20060105172532.000[-5:EST]"]];
  [statement setDateEnd:[dateFormatter dateFromString:@"20060131172532.000[-4:EST]"]];
  
  // build up transactions
  OFXBuyMutualFund* trn1 = [[OFXBuyMutualFund alloc] init];
  [trn1 setTradeDate:[dateFormatter dateFromString:@"20060119000000.000[-5:EST]"]];
  [trn1 setUniqueId:@"212839062820295310723"];
  OFXSecurity* mutualFund = [[OFXSecurity alloc] init];
  [mutualFund setUniqueId:@"744316100"];
  [mutualFund setUniqueIdType:@"CUSIP"];
  [trn1 setSecurity:mutualFund];
  [trn1 setUnits:[NSNumber numberWithDouble:14.6860]];
  [trn1 setUnitPrice:[NSNumber numberWithDouble:18.9000]];
  [trn1 setTotalAmount:[NSNumber numberWithDouble:-277.5700]];
  OFXCurrency* trnCurrency = [[OFXCurrency alloc] init];
  [trnCurrency setCurrencySymbol:@"USD"];
  [trnCurrency setExchangeRate:[NSNumber numberWithDouble:1.0000]];
  [trn1 setCurrency:trnCurrency];
  [trn1 setSecuritySubAccount:@"OTHER"];
  [trn1 setFundingSubAccount:@"OTHER"];
  [trn1 setLoanId:@"2"];
  [trn1 setLoanPrincipal:[NSNumber numberWithDouble:277.5700]];
  [trn1 setLoanInterestRate:[NSNumber numberWithDouble:0.000]];
  [trn1 setInvestment401kSource:@"ROLLOVER"];
  [trn1 setDateOfPayrollDeduction:[dateFormatter dateFromString:@"20060114000000.000[-5:EST]"]];
  [trn1 setPriorYear401kContribution:NO];
  [trn1 setBuyType:@"BUY"];
  
  OFXBuyMutualFund* trn2 = [[OFXBuyMutualFund alloc] init];
  [trn2 setTradeDate:[dateFormatter dateFromString:@"20060119000000.000[-5:EST]"]];
  [trn2 setUniqueId:@"212839062820510822977"];
  [trn2 setSecurity:mutualFund];
  [trn2 setUnits:[NSNumber numberWithDouble:2.0220]];
  [trn2 setUnitPrice:[NSNumber numberWithDouble:18.9000]];
  [trn2 setTotalAmount:[NSNumber numberWithDouble:-38.2200]];
  [trn2 setCurrency:trnCurrency];
  [trn2 setSecuritySubAccount:@"OTHER"];
  [trn2 setFundingSubAccount:@"OTHER"];
  [trn2 setLoanId:@"2"];
  [trn2 setLoanPrincipal:[NSNumber numberWithDouble:0.0000]];
  [trn2 setLoanInterestRate:[NSNumber numberWithDouble:38.2200]];
  [trn2 setInvestment401kSource:@"ROLLOVER"];
  [trn2 setDateOfPayrollDeduction:[dateFormatter dateFromString:@"20060114000000.000[-5:EST]"]];
  [trn2 setPriorYear401kContribution:NO];
  [trn2 setBuyType:@"BUY"];
  
  OFXBuyMutualFund* trn3 = [[OFXBuyMutualFund alloc] init];
  [trn3 setTradeDate:[dateFormatter dateFromString:@"20060106000000.000[-5:EST]"]];
  [trn3 setUniqueId:@"212849815151950488609"];
  [trn3 setSecurity:mutualFund];
  [trn3 setUnits:[NSNumber numberWithDouble:4.9010]];
  [trn3 setUnitPrice:[NSNumber numberWithDouble:18.7900]];
  [trn3 setTotalAmount:[NSNumber numberWithDouble:-92.0900]];
  [trn3 setCurrency:trnCurrency];
  [trn3 setSecuritySubAccount:@"OTHER"];
  [trn3 setFundingSubAccount:@"OTHER"];
  [trn3 setInvestment401kSource:@"PRETAX"];
  [trn3 setDateOfPayrollDeduction:[dateFormatter dateFromString:@"20051231000000.000[-5:EST]"]];
  [trn3 setPriorYear401kContribution:YES];
  [trn3 setBuyType:@"BUY"];
  
  NSMutableArray* transactions = [NSMutableArray arrayWithObjects:trn1, trn2,
                                  trn3, nil];
  [statement setTransactions:transactions];
  [statement setPreTaxSecurityValue:[NSNumber numberWithDouble:31690.340000]];
  [statement setValueOfSecuritiesPurchasedWithProfitSharing:[NSNumber numberWithDouble:10725.640000]];
  [statement setValueOfRollOverSecurities:[NSNumber numberWithDouble:15945.75]];
  [statement setValueOfSecuritiesPurchasedWithOtherVestingFunds:[NSNumber numberWithDouble:108.80]];
  [statement setTotalAmount:[NSNumber numberWithDouble:58470.53]];
  [statement setEmployerName:@"ELGIN NATIONAL INDUSTRIES INC"];
  [statement setPlanId:@"4343"];
  [statement setPlanJoinDate:[dateFormatter dateFromString:@"19940101000000.000[-5:EST]"]];
  [statement setDollarForDollarMatchPercent:[NSNumber numberWithInt:0.00]];
  OFX401kContribution* contrib1 = [[OFX401kContribution alloc] init];
  [contrib1 setSecurity:mutualFund];
  [contrib1 setPreTaxContributionPercent:[NSNumber numberWithInt:50]];
  [contrib1 setProfitSharingContributionPercent:[NSNumber numberWithInt:100]];
  [contrib1 setRolloverContributionPercent:[NSNumber numberWithInt:100]];
  [contrib1 setOtherVestingContributionPercent:[NSNumber numberWithInt:100]];
  
  OFX401kContribution* contrib2 = [[OFX401kContribution alloc] init];
  OFXSecurity* security1 = [[OFXSecurity alloc] init];
  [security1 setUniqueId:@"74431M105"];
  [security1 setUniqueIdType:@"CUSIP"];
  [contrib2 setSecurity:security1];
  [contrib2 setPreTaxContributionPercent:[NSNumber numberWithInt:25]];
  [contrib2 setProfitSharingContributionPercent:[NSNumber numberWithInt:0]];
  [contrib2 setRolloverContributionPercent:[NSNumber numberWithInt:0]];
  [contrib2 setOtherVestingContributionPercent:[NSNumber numberWithInt:0]];
  
  OFX401kContribution* contrib3 = [[OFX401kContribution alloc] init];
  OFXSecurity* security2 = [[OFXSecurity alloc] init];
  [security2 setUniqueId:@"743969107"];
  [security2 setUniqueIdType:@"CUSIP"];
  [contrib3 setSecurity:security1];
  [contrib3 setPreTaxContributionPercent:[NSNumber numberWithInt:25]];
  [contrib3 setProfitSharingContributionPercent:[NSNumber numberWithInt:0]];
  [contrib3 setRolloverContributionPercent:[NSNumber numberWithInt:0]];
  [contrib3 setOtherVestingContributionPercent:[NSNumber numberWithInt:0]];
  
  [[statement contributionInfo] addObject: contrib1];
  [[statement contributionInfo] addObject: contrib2];
  [[statement contributionInfo] addObject: contrib3];
  
  OFX401kSummaryInfo* summary = [[OFX401kSummaryInfo alloc] init];
  [summary setPreTaxContributions:[NSNumber numberWithDouble:843.25]];
  [summary setAfterTaxContributions:[NSNumber numberWithDouble:43.42]];
  [summary setMatchingContributions:[NSNumber numberWithDouble:421.62]];
  [summary setTotalContributions:[NSNumber numberWithDouble:1308.29]];
  [dateFormatter setDateFormat:@"yyyyMMddhhmmss"];
  [summary setDateStart:[dateFormatter dateFromString:@"20060101000000"]];
  [summary setDateEnd:[dateFormatter dateFromString:@"20060131000000"]];
  
  [statement setYearToDateSummaryInfo:summary];
  
  STAssertEqualObjects([[document statements] objectAtIndex:0], statement,
                       @"Statement");
}

@end
